package com.zzw.springboot.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author zzw2000
 * @Date 2022年05月14日 19:17
 * @Description 接口统一返回包装类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public static Result success() {
        return new Result(Constants.CODE_200, "", null);
    }

    public static <T> Result success(T data) {
        return new Result(Constants.CODE_200, "", data);
    }

    public static Result error() {
        return new Result(Constants.CODE_500, "服务器异常", null);
    }

    public static Result error(ErrorResult errorResult) {
        return new Result(errorResult.getErrorCode(), errorResult.getErrorMsg(), null);
    }
}
